package com.xfcy.blog.controller.system;



import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.annotation.OperationLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.dto.TagDTO;
import com.xfcy.blog.service.TagsService;
import com.xfcy.blog.valid.AddGroup;
import com.xfcy.blog.valid.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 博客标签表(Tags)表控制层
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:06
 */
@RestController
@RequestMapping("system/tags")
@Api(tags = "博客标签管理")
public class TagsController {

    @Resource
    private TagsService tagsService;

    @GetMapping("/list")
    @ApiOperation(value = "后台标签分页", httpMethod = "GET", response = R.class, notes = "后台标签分页")
    @SaCheckLogin
    public R list(Integer pageNo, Integer pageSize, String name) {
        return tagsService.listByRecord(pageNo, pageSize, name);
    }

    @OperationLogger(value = "置顶或取消置顶")
    @GetMapping("/top")
    @SaCheckPermission("/system/tags/top")
    @ApiOperation(value = "置顶或取消置顶", httpMethod = "GET", response = R.class, notes = "置顶或取消置顶")
    public R top(Long id) {
        return tagsService.top(id);
    }

    @OperationLogger(value = "删除标签")
    @RequestMapping(value = "/remove",method = RequestMethod.DELETE)
    @SaCheckPermission("/system/tags/remove")
    @ApiOperation(value = "删除标签", httpMethod = "DELETE", response = R.class, notes = "删除标签")
    public R deleteById(Long  id){
        return tagsService.deleteById(id);
    }

    @OperationLogger(value = "批量删除标签")
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.DELETE)
    @SaCheckPermission("/system/tags/deleteBatch")
    @ApiOperation(value = "批量删除标签", httpMethod = "DELETE", response = R.class, notes = "批量删除标签")
    public R deleteBatch(@RequestBody List<Long> ids){
        return tagsService.deleteBatch(ids);
    }

    @OperationLogger(value = "添加标签")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @SaCheckPermission("/system/tags/add")
    @ApiOperation(value = "添加标签", httpMethod = "POST", response = R.class, notes = "添加标签")
    public R add(@Validated(AddGroup.class) @RequestBody TagDTO tagDTO) {
        return tagsService.addTag(tagDTO);
    }

    @OperationLogger(value = "更改标签")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @SaCheckPermission("/system/tags/update")
    @ApiOperation(value = "更改标签", httpMethod = "POST", response = R.class, notes = "更改标签")
    public R update(@Validated(UpdateGroup.class) @RequestBody TagDTO tagDTO) {
        return tagsService.updateTag(tagDTO);
    }

    @OperationLogger(value = "标签详情")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @SaCheckPermission("/system/tags/info")
    @ApiOperation(value = "标签详情", httpMethod = "GET", response = R.class, notes = "标签详情")
    public R getTagsById(Long id) {
        return tagsService.getTagsById(id);
    }


}

